package com.example.cato_api.controller;

import com.example.cato_entity.entity.Ingredient;
import com.example.cato_entity.entity.Taco;
import lombok.Getter;
import org.springframework.hateoas.CollectionModel;
import org.springframework.hateoas.RepresentationModel;

import java.util.Date;
import java.util.List;

/*
  继承了RepresentationModel 从而继承了一个Link对象和管理链表的方法
 */
public class TacoEntityModel extends RepresentationModel<TacoEntityModel> {

    private static final IngredientEntityModelAssembler ingredientAssembler = new IngredientEntityModelAssembler();

    @Getter
    private String name;

    @Getter
    private final Date createAt;

    @Getter
    private final CollectionModel<IngredientEntityModel> ingredients;


    public TacoEntityModel(Taco taco) {
        this.name = taco.getName();
        this.createAt = taco.getCreatedAt();
        this.ingredients = ingredientAssembler.toCollectionModel(taco.getIngredients());
    }
}
